<script type ="text/javascript" src="../date/jquery.jdpicker.js"></script>
<link rel="stylesheet" href="../date/jdpicker.css" type="text/css" media="screen" /> 
<script type="text/javascript">
	function XemTheoNgayXuLy()
	{
		document.xemtheongay.submit(); 
	}
</script>



<?php
	$NgayBatDau = $_POST["NgayBatDau"];
	$NgayKetThuc = $_POST["NgayKetThuc"];
	if (!isset($NgayBatDau))
	{
		$NgayBatDau = $_GET['NgayBatDau'];
	}
	if (!isset($NgayKetThuc))
	{
		$NgayKetThuc = $_GET['NgayKetThuc'];
	}
	$kekhaigiaodich = new kekhaigiaodichbs();
	
	if(trim($NgayBatDau)=="" || trim($NgayKetThuc)=="" || strtotime($NgayBatDau) > strtotime($NgayKetThuc))
		$danhsach = $kekhaigiaodich->LayDanhSach();
	else 
	{
		$kekhaigiaodich->NgayBatDau = $NgayBatDau;
		$kekhaigiaodich->NgayKetThuc = $NgayKetThuc;
		$danhsach = $kekhaigiaodich->LayDanhSachKhoangNgay();
	}
	session_start();
	$nhatky = new nhatkybs();
	$nhatky->TenSuKien = "Xem danh sách kê khai giao dịch";
	$nhatky->MaNguoiDung = $_SESSION["MaND"];
	date_default_timezone_set('Asia/Ho_Chi_Minh');
	$nhatky->ThoiGian = date("Y-m-d H:m:s", time());
	$nhatky->Them();
?>
<table id="rounded-corner" class="display" summary="Danh sách kê khai giao dịch" border="1">	
	<thead>
		<tr>
			<th align="center" colspan="10">
	               	<h2><strong>DANH SÁCH KÊ KHAI GIAO DỊCH</strong></h2>
			</th>
		</tr>
		<tr>		
			<th scope="col" class="rounded">Số TT</th>
			<th scope="col" class="rounded">Số bút toán</th>
			<th scope="col" class="rounded">Loại giao dịch</th>
			<th scope="col" class="rounded">Số sổ</th>
			<th scope="col" class="rounded">Số khế ước</th>
			<th scope="col" class="rounded">Nhân viên</th>
			<th scope="col" class="rounded">Phòng giao dịch</th>
			<th scope="col" class="rounded">Ngày giao dịch</th>
			<th scope="col" class="rounded">Số tiền TK nợ</th>
			<th scope="col" class="rounded">Số tiền TK có</th>
		</tr>
	</thead>
	<tbody>
		<?php
				$stt = 1;
				for($i = 0; $i < ($danhsach == false ? 0 : count($danhsach)); $i++)
				{
					echo "<tr>";
					echo "<td>" . ($i + 1) . "</td>";
					echo "<td>{$danhsach[$i]['SoButToan']}</td>";
					$db = new loaigiaodichbs();
					$db->MaLoaiGiaoDich = $danhsach[$i]['MaLoaiGiaoDich'];
					$danhsachdb = $db->LayDanhSach();
					echo "<td>{$danhsachdb[0]['TenLoaiGiaoDich']}</td>";
					echo "<td>{$danhsach[$i]['MaSoTietKiem']}</td>";
					echo "<td>{$danhsach[$i]['SoKheUoc']}</td>";
					$nguoidung = new nguoidungbs();
					$nguoidung->MaNguoiDung =  $_SESSION['MaND'];
					$dsnguoidung = $nguoidung->LayDanhSach();
					$HoTen = $dsnguoidung[0]['Ho'].' '.$dsnguoidung[0]['Ten'];
					echo "<td>{$HoTen}</td>";
					$phonggiaodich = new phonggiaodichbs();
					$phonggiaodich->MaPhongGD = $dsnguoidung[0]['MaPhongGD'];
					$dsphonggiaodich = $phonggiaodich->LayDanhSach();
					echo "<td>{$dsphonggiaodich[0]['TenPhongGD']}</td>";
					echo "<td>{$danhsach[$i]['NgayGiaoDich']}</td>";
					echo "<td>{$danhsach[$i]['SoTienTaiKhoanNo']}</td>";
					echo "<td>{$danhsach[$i]['SoTienTaiKhoanCo']}</td>";
					echo "</tr>";
					$stt++;
				}	
			?>
	</tbody>
</table>
<br/>
<br/>
<form id="xemtheongay" name ="xemtheongay" method="post" action="index.php?do=kekhaigiaodich">
<table style="width: 950px">
		<tr>
			<td style="padding-top:10px;">
				<label for="tungay">Từ ngày:</label>  
			</td>
			<td style="padding-top:10px;">  
				<input style="text-align: center;" class="jdpicker" type="text" name="NgayBatDau" size="30" value=""/>
			</td>
			<td style="padding-top:10px;">
				<label for="denngay">Đến ngày:</label>  
			</td>
			<td style="padding-top:10px;">  
				<input style="text-align: center;" class="jdpicker" type="text" name="NgayKetThuc" size="30" value=""/>
			</td>
			<td width="30%">
				 <a href="javascript:XemTheoNgayXuLy();" class="button small blue">Xem theo ngày</a>	
			</td>
		</tr>
</table>
<br/><br/><br/>
<table style="width: 950px">
		<tr>
			<td align="center">
                <input type="button" id="print_button"  value="" title="In kê khai giao dịch" onclick="InTrang();" /> In kê khai giao dịch     
			</td>
		</tr>
</table>
</form>
<script type="text/javascript">
function InTrang()
{ 
	  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
	      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
	  var content_vlue = document.getElementById("rounded-corner").outerHTML; 
	  
	  var docprint=window.open("","",disp_setting); 
	   docprint.document.open(); 
	   docprint.document.write('<html><head><title>Quỹ tín dụng Mỹ Hòa</title>'); 
	   docprint.document.write('</head><body onLoad="self.print()"><center>');          
	   docprint.document.write(content_vlue);          
	   docprint.document.write('</center></body></html>'); 
	   docprint.document.close(); 
	   docprint.focus(); 
}
</script>
<script type="text/javascript">
	$('.jdpicker').jdPicker({date_format: 'YYYY-mm-dd'});
</script>